#include "sCICheckbox.h"
#include "sComponentCheckbox.h"
#include "sCRIFrame.h"
#include "sActionHandlerPress.h"
#include "sGUI.h"

namespace sgui
{
namespace inst
{

sComponentInstanceCheckbox::sComponentInstanceCheckbox(sGUI& gui, const res::sComponentObject& object, sComponentInstance* parent) :
	sComponentInstanceButton(gui, object, parent),
    m_checked(false)
{

}
    
void sComponentInstanceCheckbox::OnEventPressed()
{
    setChecked(!getChecked());
    sComponentInstanceButton::OnEventPressed();
}
    
void sComponentInstanceCheckbox::setChecked(const bool& value)
{
    m_checked = value;
    
    sComponentRectInstance *rect = getRequiredComponentRect(res::sComponentCheckbox::REQUIRED_RECT_CHECK_FRAME);
    sComponentRectFrame *rect_frame = static_cast<sComponentRectFrame*>(rect);

    rect_frame->setFrameState(m_checked ? res::sComponentCheckbox::FRAME_ID_CHECKED : res::sComponentCheckbox::FRAME_ID_UNCHECKED);
}
    
bool sComponentInstanceCheckbox::OnPress(const obs::sMousePressEvent& event, sComponentRectInstance* rect)
{
    if (sComponentInstanceButton::OnPress(event, rect))
    {
        return true;
    }

    return false;
}

sComponentInstanceCheckbox::~sComponentInstanceCheckbox()
{
	//
}

};
};